home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / SDKs / ScreenLight™ 1.0.1 / CodeExamples / More Code / JulesModule.c < prev   
Encoding:
C/C++ Source or Header  |  1996-02-16  |  5.7 KB  |  232 lines  |  [TEXT/MMCC]

  1. /**********************************************************************************
  2.   ExampleModule.c
  3.  
  4.  
  5.         DOCUMENTATION
  6.  
  7.                 an example module for Meddle, the Fat Binary
  8.  
  9.  
  10.         MODULE CODE RESOURCES
  11.  
  12.         HISTORY
  13.  
  14.         Copyright )WORK-IN_PROGRESS  Noesis Software Construction
  15. **********************************************************************************/
  16.  
  17. #include <Memory.h>
  18.  
  19. #include "ModuleRoutines.h"
  20. #include "Jules.h"
  21.  
  22. // ANSI math functions use globals, so we need to set up A4 (I think)
  23. // Actually, it seems to work fine without it . . . 
  24. //#include "A4Stuff.h"
  25. //#include "SetupA4.h"
  26.  
  27. short GetBestRect( Rect *r);
  28.  
  29. //*********************************************************************************
  30. //      ModOpen
  31. //*********************************************************************************
  32. OSErr main( ModuleParamBlkPtr mpPtr)
  33. {
  34.     OSErr                err = noErr;
  35.     JulesDataPtr        julePtr = nil;
  36.     Rect                dstR;
  37.     short                pixD;
  38.  
  39.     // allocate proc pointers
  40.     if ( (err=InitmProcs(mpPtr)) != noErr)
  41.         return err;
  42.  
  43.     // If you have your own About proc defined, use the following line
  44.     //mpPtr->mProcs.aboutProc = NewModAboutProc( ABOUTPROCNAME);
  45.  
  46.     // Allocate our private storage
  47.     julePtr = (JulesDataPtr)NewPtrClear(sizeof(JulesData));
  48.     err = MemError();
  49.     if (err != noErr)
  50.         goto error;
  51.  
  52.     // Set it up
  53.     pixD = 1;
  54.     if ( mpPtr->mInPreview) {
  55.         InitJules(julePtr, &mpPtr->mGraf->portRect);
  56.     } else {
  57.         pixD = GetBestRect( &dstR);
  58.         InitJules(julePtr, &dstR);
  59.     }
  60.     
  61.     // Check color environment
  62.     if ( pixD > 1)
  63.         julePtr->useColor = true;
  64.     else
  65.         julePtr->useColor = false;
  66.  
  67.     // store private data in extended window record
  68.     mpPtr->mStorage = (long)julePtr;
  69.     
  70.     // done
  71.     return noErr;
  72.  
  73. error:
  74.     if (julePtr != nil)
  75.         DisposPtr((Ptr)julePtr);
  76.  
  77.     return err;
  78. }
  79.  
  80. //*********************************************************************************
  81. short GetBestRect( Rect *r)
  82. {
  83.     short            bestPixSiz;
  84.     short            mostNegH, mostNegV;
  85.     Rect            bestR;
  86.     GDHandle        device;
  87.     
  88.     bestPixSiz = 0;
  89.     bestR.left = bestR.right = bestR.top = bestR.bottom = 0;
  90.     mostNegH = mostNegV = 0;
  91.         
  92.     for (device = GetDeviceList(); device != 0; device = GetNextDevice(device)) {
  93.         if (TestDeviceAttribute(device, screenDevice)
  94.           && TestDeviceAttribute(device, screenActive)) {
  95.  
  96.               // Most Colors wins              
  97.             if ( (**(**device).gdPMap).pixelSize > bestPixSiz ) {
  98.                 bestPixSiz = (**(**device).gdPMap).pixelSize;
  99.                   bestR = (**device).gdRect;
  100.               } 
  101.               // Adjust for monitors to the left of the Main Device
  102.               if ( (**device).gdRect.left < mostNegH) mostNegH = (**device).gdRect.left;
  103.               if ( (**device).gdRect.top < mostNegV) mostNegV = (**device).gdRect.top;
  104.         }
  105.     }
  106.  
  107.     *r = bestR;
  108.     r->left -= mostNegH;    r->right -= mostNegH;
  109.     r->top -= mostNegV;        r->bottom -= mostNegV;
  110.  
  111.     return bestPixSiz;
  112. }
  113.  
  114.  
  115. //*********************************************************************************
  116. //    ModDraw
  117. //
  118. //  The Port is set for you on entry. Have fun !
  119. //
  120. //*********************************************************************************
  121. OSErr ModDraw( ModuleParamBlkPtr mpPtr)
  122. {
  123.     JulesDataPtr        julePtr = (JulesDataPtr)mpPtr->mStorage;
  124. //    long                oldA4 = SetUpA4();
  125.     
  126.     //PenSize(2, 2);
  127.     GetNextPoint(julePtr);
  128.     JuliaStep(julePtr, 10, false); // Throw away first few points
  129.     JuliaStep(julePtr, 30, true); // Draw a bunch
  130.     if(Random() % 20 == 0)        
  131.         JuliaStep(julePtr, julePtr->numJuliaPts, true); // Once in a while, do 'em all
  132.  
  133. //    RestoreA4(oldA4);    //    restore A4 to saved value before returning
  134.     return noErr;
  135. }
  136.  
  137.  
  138. //*********************************************************************************
  139. //    ModClose
  140. //
  141. //    Clean-up after the party...
  142. //
  143. //*********************************************************************************
  144. OSErr ModClose( ModuleParamBlkPtr mpPtr)
  145. {
  146.     JulesDataPtr julePtr = (JulesDataPtr)mpPtr->mStorage;
  147.     
  148.     if (julePtr) {
  149.         DisposPtr((Ptr)julePtr);
  150.         mpPtr->mStorage = nil;
  151.     }
  152.  
  153.     return MemError();
  154. }
  155.  
  156.  
  157. //*************************************************
  158. //    Sample About Procedure for a Module
  159.  
  160. OSErr ABOUTPROCNAME( ModuleParamBlkPtr mpPtr);
  161. OSErr ABOUTPROCNAME( ModuleParamBlkPtr mpPtr)
  162. {
  163.     Rect            tmpR;
  164.     EventRecord        evt;
  165.     JulesDataPtr    data;
  166.     
  167.     data = (JulesDataPtr)mpPtr->mStorage;
  168.     
  169.     // GrafPort is set on entry
  170.     tmpR = mpPtr->mGraf->portRect;
  171.     EraseRect( &tmpR);
  172.     
  173.     if ( GetPortPixDepth( mpPtr->mGraf) > 1)
  174.         ForeColor( redColor);
  175.      else 
  176.          ForeColor( whiteColor);
  177.     PaintRect( &tmpR);
  178.     
  179.     while ( !WaitNextEvent( mDownMask+keyDownMask, &evt, GetCaretTime(), 0))    
  180.         ; 
  181.         
  182.     ForeColor( blackColor);
  183.     PaintRect( &tmpR);
  184.     
  185.     return;
  186. }
  187.  
  188.  
  189. //*************************************************
  190. OSErr ModChangePrefs( ModuleParamBlkPtr mpPtr)
  191. {
  192.     JulesDataPtr julePtr;
  193.     long    **tIDh;
  194.     long    tmp;
  195.     short    val;
  196.  
  197.     // We get passed in a ptr to the ModControlRecord in 
  198.     //  the mInfo fld. Our only clue to which control type
  199.     //  this is is by the first long in every ModControlRec,
  200.     //  the User-Defined ID number ! 
  201.  
  202.     //Debugger();
  203.  
  204.     julePtr = (JulesDataPtr)mpPtr->mStorage;
  205.     tIDh = (long**)mpPtr->mInfo;
  206.  
  207.     switch (**tIDh) {
  208.         case 1:                            // Slider
  209.             {
  210.                 ScSLD_SliderRec **tScSLD_RecH;
  211.                 // we have a horizSlider
  212.         
  213.                 tScSLD_RecH = (ScSLD_SliderRec **)mpPtr->mInfo;
  214.                 val = (*tScSLD_RecH)->curValue;
  215.                 // map 0-100 to kNumJuliaPts/4 to kNumJuliaPts*2
  216.                 //  x/100 * 1.75k + .25k
  217.                 tmp = val/100 * 7 * kNumJuliaPts + (kNumJuliaPts >> 1);
  218.                 julePtr->numJuliaPts = tmp >> 3;
  219.         
  220.             }
  221.             break;
  222.     
  223.         };
  224.  
  225.     return noErr;
  226. }
  227.  
  228.  
  229.  
  230.  
  231. //**********************************************************************************
  232. //                                                      E N D   O F   L I S T I N G                                                            E N D   O F   L I S T I N G